<?php
/**
 * 用户逻辑层
 *
 */

namespace App\Utils;

class Ip
{
    /**
     * 获取客户端ip地址
     * @return mixed
     */
    public function ip( array $res)
    {
        if (isset($res['http_client_ip'])) {
            return $res['http_client_ip'];
        } elseif (isset($res['http_x_real_ip'])) {
            return $res['http_x_real_ip'];
        } elseif (isset($res['http_x_forwarded_for'])) {
            //部分CDN会获取多层代理IP，所以转成数组取第一个值
            $arr = explode(',', $res['http_x_forwarded_for']);
            return $arr[0];
        } else {
            return $res['remote_addr'];
        }


    }
}
